#Twisted Shootout
#Copyright (C) 2007  Han Dao
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

#You can contact the author at wikipediankiba@gmail.com
import pygame

class MapLaw:
	def __init__(self,maposition):
		self.position = maposition
		self.p = self.position.p
		self.e = self.position.e
		self.i = self.position.i
		self.state = 0
	def load(self,collide):
		self.collide = collide
		self.collide.add(self.position.mapobj,self.position.i)
	def compute(self):
		self.collide.wincollide()
		self.revert(self.p)
		for e in self.e.e:
			self.revert(e)
		self.bullet()
		self.items()
	def revert(self,actor):
		s = self.collide.map_collide(actor)
		if s == 1:
			actor.rect.x = actor.retainer[0]
			actor.rect.y = actor.retainer[1]
		else:
			if actor.status != True:
				if actor.rect.y < 550:
					actor.rect.y = actor.rect.y + 5
					s = self.collide.map_collide(actor)
					if s == 1:
						actor.rect.y = actor.rect.y - 5
					if actor.rect.y > 550:
						actor.rect.y = 550
	def bullet(self):
		self.collide.bulletobj()
	def items(self):
		n = self.collide.itemsobj()
		if n == -1:
			return
		self.i.sprites.remove(self.i.items[n])
		self.i.items.pop(n)
		